﻿// ----------------------------------------------------------------------
// <copyright file="PlaylistBuilder.cs" company="Axitech">
//     Copyright (c) Axitech. All rights reserved.
// </copyright>
// <author>Anton Prilepskiy</author>
// <email>a.prilepskiy@axitech.ru</email>
// <cvs>$Id$</cvs>
// ----------------------------------------------------------------------

namespace Axitech.PlaylistCreator.Playlist
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Class for generating playlist
    /// </summary>
    public class PlaylistBuilder
    {
        public PlaylistBuilder()
        {
            this.Elements = new List<PlaylistElement>();
            this.HttpCaching = 1200;
        }

        public IList<PlaylistElement> Elements { get; private set; }

        public Int32 HttpCaching { get; set; }

        public String GetPlaylist()
        {
            var sb = new StringBuilder();
            sb.AppendLine("#EXTM3U");
            
            foreach (var em in this.Elements)
            {
                sb.AppendFormat("#EXTVLCOPT:http-caching={1}{0}#EXTINF:0, {2}{0}{3}{0}", Environment.NewLine, this.HttpCaching, em.Title, em.Url);
            }
            
            return sb.ToString();
        }
    }
}
